<template>
  <div class="approval-node" :class="{ selected: selected }">
    <div class="node-content">
      <el-icon class="node-icon"><User /></el-icon>
      <div class="node-text">
        <div class="node-title">{{ data?.name || '审批' }}</div>
        <div class="node-subtitle">
          {{ getApproverText() }}
        </div>
      </div>
    </div>
    <Handle
      id="target"
      type="target"
      :position="Position.Left"
      :style="{ background: '#409eff', width: '20px', height: '20px', border: '3px solid #fff', boxShadow: '0 0 8px #409eff', zIndex: 2, cursor: 'pointer' }"
    />
    <Handle
      id="source"
      type="source"
      :position="Position.Right"
      :style="{ background: '#409eff', width: '20px', height: '20px', border: '3px solid #fff', boxShadow: '0 0 8px #409eff', zIndex: 2, cursor: 'pointer' }"
    />
  </div>
</template>

<script setup lang="ts">
import { Handle, Position } from '@vue-flow/core'
import { ElIcon } from 'element-plus'
import { User } from '@element-plus/icons-vue'

const props = defineProps({
  id: String,
  data: Object,
  selected: Boolean
})

const getApproverText = () => {
  const approvers = props.data?.approvers || []
  if (approvers.length === 0) {
    return '请选择审批人'
  }
  if (approvers.length === 1) {
    return approvers[0].name
  }
  return `${approvers.length}个审批人`
}

defineOptions({
  name: 'ApprovalNode'
})
</script>

<style scoped>
.approval-node {
  padding: 12px 16px;
  border-radius: 12px;
  background: linear-gradient(135deg, #3b82f6 0%, #60a5fa 100%);
  color: white;
  min-width: 140px;
  border: 2px solid transparent;
  transition: all 0.3s ease;
  position: relative;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.approval-node.selected {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3), 0 8px 24px rgba(59, 130, 246, 0.4);
  transform: scale(1.02);
}

.approval-node:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(59, 130, 246, 0.4);
}

.node-content {
  display: flex;
  align-items: center;
  gap: 10px;
}

.node-icon {
  font-size: 22px;
  color: white;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1));
}

.node-text {
  flex: 1;
}

.node-title {
  font-weight: 600;
  font-size: 14px;
  line-height: 1.3;
  letter-spacing: 0.3px;
}

.node-subtitle {
  font-size: 11px;
  opacity: 0.9;
  margin-top: 3px;
  font-weight: 400;
}

::v-deep(.vue-flow__handle) {
  border-radius: 50% !important;
  border: 3px solid #fff !important;
  box-shadow: 0 0 8px #409eff !important;
  width: 20px !important;
  height: 20px !important;
  z-index: 2 !important;
  cursor: pointer !important;
}
</style> 